/*
 * Menu.h
 *
 * Created: 2012-06-12 20:23:01
 *  Author: Sebastian_2
 */ 

// Originally written by Dean Camera as MICRO-MENU, modified and suited for personal needs by me


#ifndef MENU_H_
#define MENU_H_

#include "DataTypes.h"
#include <avr/pgmspace.h>

// Typedefs:
typedef void (*FuncPtr)(void);

typedef struct {
	point Start;
	point End;
	FuncPtr TouchFunc;
} TouchItem;

typedef const struct PROGMEM {
	FuncPtr     EnterFunc;
	uint8_t		ItemsNum;
	TouchItem	*ItemArray;
} Menu_Item;

// Externs:
//extern WriteFuncPtr*    WriteFunc;
extern const Menu_Item  Null_Menu;
extern Menu_Item*       CurrMenuItem;

// Defines and Macros:
#define NULL_ENTRY Null_Menu
#define NULL_FUNC  (void*)0
#define NULL_TEXT  0x00

#define ENTERFUNC  *((FuncPtr*)pgm_read_word(&CurrMenuItem->EnterFunc))
#define	ITEMSNUM   (uint8_t)pgm_read_byte(&CurrMenuItem->ItemsNum)
#define ITEMSARRAY *((TouchItem*)pgm_read_word(&CurrMenuItem->ItemArray))

#define MAKE_MENU(Name, EnterFunc, ItemsNum, ItemArray) \
	Menu_Item Name = {(FuncPtr)EnterFunc, (uint8_t)ItemsNum, (TouchItem*)ItemArray}

#define SET_MENU(x) \
	MenuChange((Menu_Item*)&x);
	
#define GO_MENU_FUNC(x)  \
	MenuFunc((FuncPtr*)&x)
	
#define EXTERN_MENU(Name) \
    extern Menu_Item Name;

// Prototypes:
void MenuChange(Menu_Item* NewMenu);
void MenuFunc(FuncPtr* Function);



#endif /* MENU_H_ */